package flc.ast.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;

import com.blankj.utilcode.util.ToastUtils;

import flc.ast.BaseAc;
import flc.ast.HomeActivity;
import flc.ast.R;
import flc.ast.databinding.ActivitySetAnswerBinding;
import flc.ast.utils.Content;
import stark.common.basic.utils.SPUtil;

public class SetAnswerActivity extends BaseAc<ActivitySetAnswerBinding> {

    public static String password;
    private String question;
    private String answer;


    @Override
    protected int onCreate() {
        return R.layout.activity_set_answer;
    }

    @Override
    protected void initView() {
        mDataBinding.ivSetAnswerBack.setOnClickListener(v -> onBackPressed());

        mDataBinding.ivCancel.setOnClickListener(v -> onBackPressed());
        mDataBinding.ivConfirm.setOnClickListener(this);
    }

    @Override
    protected void onClickCallback(View v) {
        switch (v.getId()) {
            case R.id.ivConfirm://确定
                question = mDataBinding.etQuestion.getText().toString();
                answer = mDataBinding.etAnswer.getText().toString();
                if (TextUtils.isEmpty(question)) {
                    ToastUtils.showShort(getString(R.string.please_input_question));
                    return;
                }
                if (TextUtils.isEmpty(answer)) {
                    ToastUtils.showShort(getString(R.string.please_input_answer));
                    return;
                }
                SPUtil.putString(mContext, Content.myPassword, password);
                SPUtil.putString(mContext, Content.myAnswer, answer);
                SPUtil.putString(mContext, Content.myProblem, question);
                SPUtil.putBoolean(mContext, Content.isHavePassword, true);
                ToastUtils.showShort(getString(R.string.password_set_suc));
                startActivity(HomeActivity.class);
                break;
        }
    }

    @Override
    protected void initData() {

    }
}